import {Component,OnDestroy} from '@angular/core';
import { Router } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
import { LoginPageProvider } from './login.page.provider';
import { Location } from '@angular/common';

@Component({
    selector:'login-page',
    templateUrl:'./login.page.html',
    styleUrls:['./login.page.css'],
    providers:[LoginPageProvider]
})

export class LoginPage{

    user:any = {
        username:'zyc',
        password:'123456',
        remember:''
    };
    constructor(private service:LoginPageProvider,private location:Location){}

    login(){
        if(this.user.username !='' && this.user.password !=''){
            this.getHttp(this.user);
        }
    }

    ngOnDestroy(){
        if(this.ajaxSub){
            this.ajaxSub.unsubscribe();
        }
    }

    ajaxSub:Subscription;
    getHttp(param){
        this.ajaxSub = this.service.login(param).subscribe((res:any)=>{
            if(res.success){
                this.location.back();
            }
        });
    }
}